package com.audi.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.audi.R;
import com.audi.dto.HomeBoxItem;

public class HomeBoxSettingAdapter extends BaseAdapter {
	private Activity mActivity;
	private ArrayList<HomeBoxItem> mArrItemset;

	// private AudiDialog mDialogRootAccess;
	// int posit;

	public HomeBoxSettingAdapter(Activity activity,
			ArrayList<HomeBoxItem> mListTriggerArr) {
		this.mActivity = activity;
		this.mArrItemset = mListTriggerArr;
	}

	public void swapItems(ArrayList<HomeBoxItem> mHomeBoxList) {
		this.mArrItemset = mHomeBoxList;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return mArrItemset.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mArrItemset.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HomeBoxItem homeBoxItem = mArrItemset.get(position);
		ViewHolder viewHolder = null;
		LayoutInflater mInflater = (LayoutInflater) mActivity
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = mInflater
					.inflate(R.layout.item_homebox_setting, null);
			viewHolder.txtItem = (TextView) convertView
					.findViewById(R.id.txt_item);
			viewHolder.txtname = (TextView) convertView
					.findViewById(R.id.txt_name_setting);
			viewHolder.imvTranView = (ImageView) convertView
					.findViewById(R.id.imv_tran_view);
			viewHolder.layoutitem = (LinearLayout) convertView
					.findViewById(R.id.item_setting_hb);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.txtItem.setText(homeBoxItem.getNameItemLeft());
		if (homeBoxItem.getNameItemRight() != "") {
			viewHolder.txtname.setText(homeBoxItem.getNameItemRight());
			viewHolder.txtname.setVisibility(View.VISIBLE);
		} else if (homeBoxItem.getNameItemRight() == "") {
			viewHolder.txtname.setVisibility(View.GONE);

		}
		if (homeBoxItem.getImageVisible()) {
			viewHolder.imvTranView.setImageResource(R.drawable.icon_next);
			viewHolder.imvTranView.setVisibility(View.VISIBLE);
		} else {

			viewHolder.imvTranView.setVisibility(View.GONE);
		}

		return convertView;
		// holder.lnlRowSmartTrigger.setAlpha(0.3f);
	}

	static class ViewHolder {
		private TextView txtItem;
		private TextView txtname;
		private LinearLayout layoutitem;
		private ImageView imvTranView;
	}

	public class item_box_set {

		String nameitemleft;
		String nameitemright;

		public item_box_set(String name1, String name2) {
			nameitemleft = name1;
			nameitemright = name2;
		}

		public String getNameitemleft() {
			return nameitemleft;
		}

		public void setNameitemleft(String nameitemleft) {
			this.nameitemleft = nameitemleft;
		}

		public String getNameitemright() {
			return nameitemright;
		}

		public void setNameitemright(String nameitemright) {
			this.nameitemright = nameitemright;
		}
	}
}
